package org.example.mqtexxt.mqserver.core;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.HashMap;
import java.util.Map;

public class MSGQueue {

    private String name;

    private boolean durable = false;

    private boolean exclusive  =  false;

    private boolean autoDelete = false;

    private Map<String,Object> arguments = new HashMap<>();

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isDurable() {
        return durable;
    }

    public void setDurable(boolean durable) {
        this.durable = durable;
    }

    public boolean isExclusive() {
        return exclusive;
    }

    public void setExclusive(boolean exclusive) {
        this.exclusive = exclusive;
    }

    public boolean isAutoDelete() {
        return autoDelete;
    }

    public void setAutoDelete(boolean autoDelete) {
        this.autoDelete = autoDelete;
    }

    public String getArguments() throws JsonProcessingException {
        //把当前的argumenets转换成了String之后传递给Mybatis
        ObjectMapper objectMapper  = new ObjectMapper();
        return objectMapper.writeValueAsString(arguments);
    }
    public void setArguments(String argumentsJson) throws JsonProcessingException {
        //把参数argumentsJson按照json格式进行解析，转成Map对象
        ObjectMapper objectMapper = new ObjectMapper();
        this.arguments =  objectMapper.readValue(argumentsJson, new TypeReference<HashMap<String,Object>>() {});
    }

    public Object getArguments(String key){
        return arguments.get(key);
    }

    public void setArguments(String key, Object value){
        arguments.put(key,value);
    }
}
